#include<iostream>
#include<thread>
#include<unistd.h>
#include "RingBuffer.hpp"

using namespace RingBufferModule;

void consumer(RingBuffer<int>& ring_buff)
{
    while(1)
    {
        int data;
        ring_buff.Pop(&data);

        std::cout<<"消费了一个数据"<<data<<std::endl;
    }
}
void productor(RingBuffer<int>& ring_buff)
{
    int data = 10;
    while(1)
    {
        sleep(1);
        ring_buff.Equeue(data);
        std::cout<<"生产了一个数据"<<data<<std::endl;
        data++;
    }
}

int main()
{
    //消费场所
    RingBuffer<int>* ring_buff = new RingBuffer<int>(5); //共享资源->临界资源
    std::thread c1(consumer, std::ref(*ring_buff));
    std::thread c2(consumer, std::ref(*ring_buff));
    std::thread c3(consumer, std::ref(*ring_buff));
    std::thread p1(productor, std::ref(*ring_buff));
    std::thread p2(productor, std::ref(*ring_buff));

    c1.join();
    c2.join();
    c3.join();
    p1.join();
    p2.join();

    delete ring_buff;
    return 0;
}